package com.flower.subject.domain.handler.subject;

import com.flower.subject.domain.convent.JudgeSubjectConverter;
import com.flower.subject.domain.entity.SubjectAnswerBO;
import com.flower.subject.domain.entity.SubjectInfoBO;
import com.flower.subject.domain.entity.SubjectOptionBO;
import com.flower.subject.enums.SubjectInfoTypeEnum;
import com.flower.subject.infra.basic.entity.SubjectBrief;
import com.flower.subject.infra.basic.entity.SubjectJudge;
import com.flower.subject.infra.basic.service.SubjectJudgeService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

import static com.flower.subject.domain.convent.BriefSubjectConverter.INSTANT;

/**
 * @author lavender
 * @version 1.0
 * @date 2024-07-08 14:48
 * 判断题目策略类
 */
@Component
public class JudgeTypeHandler implements SubjectTypeHandler{


    @Resource
    private SubjectJudgeService service;

    @Override
    public SubjectInfoTypeEnum getSubjectType() {
        return SubjectInfoTypeEnum.JUDGE;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        SubjectJudge subjectJudge = new SubjectJudge();
        SubjectAnswerBO subjectAnswerBO = subjectInfoBO.getOptionList().get(0);

        subjectJudge.setSubjectId(subjectInfoBO.getId().intValue());
        subjectJudge.setIsCorrent(subjectAnswerBO.getIsCorrect());

        service.insert(subjectJudge);

    }

    @Override
    public SubjectOptionBO query(Integer subjectId) {
        SubjectJudge subjectJudge = new SubjectJudge();
        subjectJudge.setSubjectId(subjectId);
        List<SubjectJudge> subjectJudges = service.queryByCondition(subjectJudge);
        List<SubjectAnswerBO> subjectAnswerBOS = JudgeSubjectConverter.INSTANT.covertAnswerBoToBOList(subjectJudges);
        SubjectOptionBO subjectOptionBO = new SubjectOptionBO();
        subjectOptionBO.setOptionList(subjectAnswerBOS);
        return subjectOptionBO;
    }
}
